package com.songshuai.pangu.api.controller;

import com.songshuai.pangu.api.service.CustMeetingService;
import com.songshuai.webapi.baseapi.dto.pangu.response.my.InvolvedActivityResDto;
import com.songshuai.webapi.baseapi.dto.pangu.response.my.SaleResDto;
import com.songshuai.webapi.baseapi.enumerations.ResultStatus;
import com.songshuai.webapi.baseapi.pojo.QueryResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;

@Slf4j
@Api("盘古客户端接口--客户助手--我")
@RestController
@RequestMapping("/api/pangu/my/")
public class MyController {

    @Autowired
    private CustMeetingService custMeetingService;

    /**
     *
     * @userId 客户ID
     * @return
     */
    @ApiOperation(value = "获取资讯顾问")
    @RequestMapping(value = "getSale", method = RequestMethod.GET)
    public CompletableFuture<QueryResponse> getSale(String userId){
        return CompletableFuture.supplyAsync(()->{

            try{
                SaleResDto saleResDto = custMeetingService.getMySale(userId);
                return QueryResponse.setResData(saleResDto);
            } catch (Exception e) {
                log.error("api/pangu/my/getSale", e);
                return new QueryResponse(ResultStatus.FAILOfficial.getErrorCode(),e.getMessage());
            }
        });
    }


    /**
     * 我参与过的活动
     * @param userId 客户ID
     * @return
     */
    @GetMapping("queryActivityList")
    public CompletableFuture<QueryResponse> queryActivityList(@RequestParam("userId")String userId){
        return CompletableFuture.supplyAsync(()->{
            try{
                List<InvolvedActivityResDto> result = custMeetingService.queryHistoryActivityList(userId);
                return QueryResponse.setResData(result);
            } catch (Exception e) {
                log.error("api/pangu/my/queryActivityList", e);
                return new QueryResponse(ResultStatus.FAILOfficial.getErrorCode(),e.getMessage());
            }
        });
    }

    /**
     * 我参与过的活动数
     * @param userId 客户ID
     * @return
     */
    @GetMapping("queryActivityCount")
    public CompletableFuture<QueryResponse> queryActivityCount(@RequestParam("userId")String userId){
        return CompletableFuture.supplyAsync(()->{
            try{
                Integer count = custMeetingService.queryHistoryActivityCount(userId);
                return QueryResponse.setResData(count);
            } catch (Exception e) {
                log.error("api/pangu/my/queryActivityList", e);
                return new QueryResponse(ResultStatus.FAILOfficial.getErrorCode(),e.getMessage());
            }
        });
    }
}
